# coding:utf-8
import sys

import pygame
from pygame.locals import *

# 初始化pygame环境
pygame.init()

# 创建一个长宽分别为800/480窗口
canvas = pygame.display.set_mode((800, 480))
canvas.fill((255, 255, 255))

# 设置窗口标题
pygame.display.set_caption("捕鱼达人")

# 加载图片
net = pygame.image.load("images/net.png")
fish = []
for i in range(10):
	# print("images/fish10_{}.png".format(i))
	fish.append(pygame.image.load("images/fish10_{}.png".format(i)))


bg = pygame.image.load("images/bg.jpg")


def handleEvent():
	for event in pygame.event.get():
		if event.type == QUIT:
			pygame.quit()
			sys.exit()


# 背景(bg)坐标为(0,0)
# 渔网(net)坐标为(300,300)
# 鱼(fish1)坐标为(300,100)
class Fish():
    def __init__(self):
        self.x = 800
        self.y = 200
        self.image = fish[0]
        self.index = 0

    def paint(self):
        self.annimation()
        canvas.blit(self.image,(self.x,self.y))

    def move(self):
        self.x -= 0.1

    def annimation(self):
        self.image = fish[int(self.index)]
        self.index += 0.02
        if self.index >= len(fish):
            self.index = 0

fish1 = Fish()

while True:
    canvas.blit(bg,(0,0))
    fish1.paint()
    fish1.move()
    pygame.display.update()
    handleEvent()